import { mutableHandlers } from './baseHandlers.js';

export const reactiveMap = new WeakMap();//是弱版本map，

export function reactive(target){
    return createReactiveObject(target,mutableHandlers,reactiveMap)

}

function createReactiveObject(target,proxyHandlers,proxyMap){
    if(typeof target !== 'object'){
        return target
    }

    const existingProxy = proxyMap.get(target)

    if(existingProxy){
        return existingProxy
    }
    
    
    const proxy = new Proxy(target,proxyHandlers)
    proxyMap.set(target,proxy)
    return proxy

}